import {def} from './utils'
import reactivify from './reactivify'
import { array_methods } from './arrayMethodsReactivify'
import Dep from './Dep'
/**
 * 将data转换成为响应式数据
 * 使包含嵌套属性的object转换为支持深响应的对象
 * @export
 * @class Observer
 */
export default class Observer {
    constructor(value) {
        this.dep = new Dep()
        value.__ob__
        def(value, '__ob__', this, false)
        console.log('Observer构造器', value)
        if (Array.isArray(value)) {
            Object.setPrototypeOf(value, array_methods)
        } else {
            this.walk(value)
        }
    }
    walk (value) {
        for(let k in value) {
            reactivify(value, k)
        }
    }
}